package dao;
import java.util.List;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import util.HibernateUtil;
import entity.FormaPagamento;
import entity.Pais;

public class FormaPagamentoDaoImplementation implements FormaPagamentoDao {

	public void save(FormaPagamento formaPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.save(formaPagamento);
		transaction.commit();
		session.close();
	}

	public void update(FormaPagamento formaPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.update(formaPagamento);
		transaction.commit();
		session.close();
	}

	public void delete(FormaPagamento formaPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.delete(formaPagamento);
		transaction.commit();
		session.close();
	}

	public void consult(FormaPagamento formaPagamento) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		formaPagamento = (FormaPagamento) session.load(FormaPagamento.class, new String("FormaPagamento"));
	}

	public FormaPagamento getFormaPagamento(long id) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		return (FormaPagamento) session.load(FormaPagamento.class, id);
	}
	
	public List<FormaPagamento> list() 
	{
	Session session = HibernateUtil.getSessionFactory().openSession();
	Transaction transaction = session.beginTransaction();
	String sql = "SELECT new FormaPagamento( f.idFormaPagamento, f.descricao) FROM FormaPagamento f";
	List<FormaPagamento> lista = session.createQuery(sql).list();
	transaction.commit();
	session.close();
	return lista;
	}
	
	

}
